import logging

import requests


class TelegramBot:
    ACCESS_TOKEN = ''
    API_BASE_URL = ''
    CHAT_ID = None

    def __init__(self):
        with open('.telegram-bot-token', 'r') as f:
            self.ACCESS_TOKEN = f.readline().strip(' \n')
            self.API_BASE_URL = f'https://api.telegram.org/bot{self.ACCESS_TOKEN}'
        with open('.telegram-bot-chat-id', 'r') as f:
            self.CHAT_ID = f.readline().strip(' \n')
        logging.debug('Token:', self.ACCESS_TOKEN)
        logging.debug('Chat id:', self.CHAT_ID)

    def send_message(self, message):
        with requests.Session() as session:
            adapter = requests.adapters.HTTPAdapter(max_retries=10)
            session.mount('https://', adapter)
            resp = session.post(
                f'{self.API_BASE_URL}/sendMessage',
                data={
                    'chat_id': self.CHAT_ID,
                    'text': message,
                    'parse_mode': 'MarkdownV2'
                }
            )
            logging.debug(resp.status_code, resp.content)
            return resp



